package com.xintoucloud.gsv.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.gsv.entity.SuperVision;
import com.xintoucloud.gsv.mapper.SuperVisionMapper;
import com.xintoucloud.gsv.model.DataGrid;
import com.xintoucloud.gsv.model.SuperVisionDto;
import com.xintoucloud.gsv.service.SuperVisionService;

@Service@Transactional
public class SuperVisionServiceImpl implements SuperVisionService{
	@Autowired
	private SuperVisionMapper superVisionMapper;
	@Override
	public void save(SuperVision superVision) {
		superVisionMapper.save(superVision);
	}
	@Override
	public List<SuperVision> list() {
		List<SuperVision> list=superVisionMapper.list();
		return list;
	}
	@Override
	public DataGrid<SuperVisionDto> listPage(int page, int size) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.count();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listPage(pageInndex, size);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setRealConfirmTime(superVision.getRealConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			//System.out.println("sidxxxxxxxxxxx:"+superVision.getSupervisionType().getSid());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	@Override
	public DataGrid<SuperVisionDto> listDraftPage(int page, int size) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listDraftPage(pageInndex, size);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	@Override
	public void deleteSuperVision(int svid) {
		superVisionMapper.deleteSuperVision(svid);
		
	}
	@Override
	public SuperVision getSuperVision(int svid) {
		return superVisionMapper.getSuperVision(svid);
	}
	@Override
	public void update(SuperVision superVision) {
		superVisionMapper.update(superVision);
		
	}
	@Override
	public DataGrid<SuperVisionDto> listMessagePage(int page, int size, int did) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listMessagePage(pageInndex, size,did);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	@Override
	public DataGrid<SuperVisionDto> listWaitRegisterPage(int page, int size) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listWaitRegisterPage(pageInndex, size);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	@Override
	public DataGrid<SuperVisionDto> listWaitDirectReply(int page, int size,int did ) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listWaitDirectReply(pageInndex, size,did);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	@Override
	public DataGrid<SuperVisionDto> listWaitDutyConfirm(int page, int size, int did) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listWaitDutyConfirm(pageInndex, size,did);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	@Override
	public DataGrid<SuperVisionDto> listWaitLeaderReply(int page, int size, int uid) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageInndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listWaitLeaderReply(pageInndex, size,uid);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	/* (non-Javadoc)
	 * @see com.xintoucloud.gsv.service.SuperVisionService#updateTime(int, java.lang.String)
	 */
	@Override
	public void updateTime(int svid, String confirmTime) {
		superVisionMapper.updateTime(svid, confirmTime);
		
	}
	@Override
	public void updateStid(int stid, int svid) {
		superVisionMapper.updateStid(stid, svid);
	}
	@Override
	public void selectDepartment(String dname) {
		superVisionMapper.selectDepartment(dname);
	}
	@Override
	public long count(int stid) {
		return superVisionMapper.countStid(stid);
	}
	@Override
	public DataGrid<SuperVisionDto> listWaitVisionConfirm(int page, int size) {
		DataGrid<SuperVisionDto> datas=new DataGrid<SuperVisionDto>();
		long totalCount=superVisionMapper.countDraft();
		int pageIndex=(page-1)*size;
		List<SuperVision> list=superVisionMapper.listWaitVisionConfirm(pageIndex, size);
		List<SuperVisionDto> list2=new ArrayList<SuperVisionDto>();
		for (SuperVision superVision : list) {
			SuperVisionDto SuperVisionDto=new SuperVisionDto();
			SuperVisionDto.setConfirmTime(superVision.getConfirmTime());
			SuperVisionDto.setDname(superVision.getDept().getDname());
			SuperVisionDto.setEndTime(superVision.getEndTime());
			SuperVisionDto.setPressMsg(superVision.getPressMsg());
			SuperVisionDto.setReplices(superVision.getReplices());
			SuperVisionDto.setSendLeader(superVision.getSendLeader());
			SuperVisionDto.setSname(superVision.getSupervisionType().getSname());
			SuperVisionDto.setStartTime(superVision.getStartTime());
			SuperVisionDto.setStid(superVision.getSuperVisionState().getSname());
			SuperVisionDto.setSvContent(superVision.getSvContent());
			SuperVisionDto.setSvid(superVision.getSvid());
			SuperVisionDto.setSvTitle(superVision.getSvTitle());
			SuperVisionDto.setSid(superVision.getSupervisionType().getSid());
			SuperVisionDto.setDid(superVision.getDept().getDid());
			list2.add(SuperVisionDto);
		}
		datas.setData(list2);
		if(list!=null) {
			datas.setCode(200);
			datas.setMsg("查询成功");
		}
		datas.setCount(totalCount);
		return datas;
	}
	
	
}
